package com.htz.java250805_library.config;

import com.htz.java250805_library.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler
    public Result handle(Exception e){
        log.info("发生异常，e:"+e);
        return Result.fail("内部错误，请联系管理员");
    }

    @ExceptionHandler
    public Result handler(NullPointerException e){
        log.error("发送异常，e",e);
        return Result.fail("发生空指针异常");
    }
    @ExceptionHandler
    public Result handler(ArithmeticException e){
        log.error("发送异常，e",e);
        return Result.fail("发生算术指针异常");
    }
    @ExceptionHandler
    public Result handler(IndexOutOfBoundsException e){
        log.error("发送异常，e",e);
        return Result.fail("发生数组越界指针异常");
    }
}


























